//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.liy.framework.common.utils;

import java.lang.reflect.Field;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Tools {
    private static Pattern linePattern = Pattern.compile("_(\\w)");
    private static Pattern humpPattern = Pattern.compile("[A-Z]");

    public Tools() {
    }

    public static void main(String[] args) {
        System.out.println(getNewUUID());
    }

    public static String getNewUUID() {
        String str = UUID.randomUUID().toString().replace("-", "");
        return str;
    }

    public static String getStringValue(Object obj) {
        return obj == null ? "" : obj.toString();
    }

    public static boolean StringIsNullOrSpace(String paramString) {
        return paramString == null || "".equals(paramString.trim()) || "NULL".equals(paramString.trim().toUpperCase()) || "undefined".equals(paramString.trim().toLowerCase());
    }

    public static boolean ObjectIsNullOrSpace(Object obj) {
        return obj == null || "".equals(obj.toString()) || "NULL".equals(obj.toString().toUpperCase());
    }

    public static boolean listIsNullOrEmpty(List list) {
        return list == null || list.size() <= 0;
    }

    public static boolean arrayIsNullOrEmpty(Object[] array) {
        return array == null || array.length <= 0;
    }

    public static String lineToHump(String str) {
        str = str.toLowerCase();
        Matcher matcher = linePattern.matcher(str);
        StringBuffer sb = new StringBuffer();

        while(matcher.find()) {
            matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
        }

        matcher.appendTail(sb);
        return sb.toString();
    }

    public static String humpToLine2(String str) {
        Matcher matcher = humpPattern.matcher(str);
        StringBuffer sb = new StringBuffer();

        while(matcher.find()) {
            matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
        }

        matcher.appendTail(sb);
        return sb.toString();
    }

    public static String toLowerCaseFirstOne(String s) {
        return Character.isLowerCase(s.charAt(0)) ? s : Character.toLowerCase(s.charAt(0)) + s.substring(1);
    }

    public static String toUpperCaseFirstOne(String s) {
        return Character.isUpperCase(s.charAt(0)) ? s : Character.toUpperCase(s.charAt(0)) + s.substring(1);
    }

    public static Object getClassValueByKey(Object obj, String key) {
        Class userCla = obj.getClass();
        Field[] fs = userCla.getDeclaredFields();

        for(int i = 0; i < fs.length; ++i) {
            Field f = fs[i];
            f.setAccessible(true);

            try {
                if (f.getName().endsWith(key)) {
                    return f.get(obj);
                }
            } catch (IllegalArgumentException var7) {
                var7.printStackTrace();
            } catch (IllegalAccessException var8) {
                var8.printStackTrace();
            }
        }

        return "";
    }

    public static void setClassValueByKey(Object obj, String key, Object value) {
        try {
            Class<?> clazz = obj.getClass();
            Field field = clazz.getDeclaredField(key);
            if (field != null) {
                field.setAccessible(true);
                field.set(obj, value);
            }
        } catch (Exception var5) {
            ;
        }

    }

    public static String strSubstring(String str, int start, int length) {
        return str.substring(start, start + length);
    }
}
